<template>
  <el-container class="homeContainer">
    <el-header>
      <div>
        <img src="@/assets/heima.png" alt="">
        <span>黑马程序员</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="shousuo" @click="shousuoClick">|||</div>
        <el-menu
          :collapse-transition="false"
          :collapse="isCollapse"
          :unique-opened="true"
          :router="true"
          :default-active="defaultActive"
          background-color="darkgray"
          text-color="#fff"
          active-text-color="#409EFF">
          <el-submenu index="2323" >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/users"  >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>用户列表</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
        <!--<el-menu
          :collapse-transition="false"
          :collapse="isCollapse"
          :unique-opened="true"
          :router="true"
          :default-active="defaultActive"
          background-color="darkgray"
          text-color="#fff"
          active-text-color="#409EFF">
          <el-submenu :index="'/'+item.path" v-for="item in menuList" :key="item.id" >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="clickMenuItem('/'+subItem.path)">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>-->
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'home',
  data() {
    return {
      menuList: [],
      isCollapse: false,
      defaultActive: window.sessionStorage.getItem("activeMenu")
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    clickMenuItem(path){
      // console.log(e.target.index)
      window.sessionStorage.setItem("activeMenu",path)
      this.defaultActive = path;
    },
    shousuoClick(){
      this.isCollapse = !this.isCollapse;
    },
    async getMenuList() {
      const { data: res } = await this.$http.get('menus');
      if(res.meta.status !== 200){
        this.$message.error(res.meta.msg)
      }else{
        this.menuList = res.data
        console.log(this.menuList)
      }
    },
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
   .el-menu {
     border-right: 0;
   }
   .homeContainer {
     height: 100%;
   }
   .el-header {
     background-color: gray;
     padding-left: 0;
     display: flex;
     justify-content: space-between;
     align-items: center;
     color: white;
     font-size: 20px;
   }
   .el-header div {
     display: flex;
     align-items: center;
   }
   .el-header div span {
     margin-left: 30px;
   }
   .el-aside {
     background-color: darkgray;
   }
   .el-main {
     background-color: #ffffff;
   }
   .shousuo {
     background-color: #1A1919;
     color: white;
     text-align: center;
     line-height: 25px;
     font-size: 15px;
     cursor: pointer;
   }
</style>
